<?php
namespace App\Http\Controllers\Home;

use App\DBs\Home\FrontDB;
use Illuminate\Http\Request;

class FrontController extends BaseController
{
    public function __construct()
    {
        $this->dbFront = new FrontDB();
    }

    //客户端统计
    public function client()
    {
//        echo '<pre>'; var_dump($_SERVER); exit;
        $res = $this->dbFront->setClient($_SERVER);
        if ($res['code']!=0) {
            return $this->toJson(-2,$res['msg']);
        }
        return $this->toJson(0);
    }

    //banner
    public function getBanner()
    {
        $res = $this->dbFront->getBanner();
        if ($res['code']!=0) {
            return $this->toJson(-2,$res['msg']);
        }
        return $this->toJson(0,'success',$res['data']);
    }

    //页面语言
    public function getLang(Request $request)
    {
        $arys = $request->all();
        $type = isset($arys['type'])&&$arys['type'] ? $arys['type'] : 0;
        $res = $this->dbFront->getLang($type);
        if ($res['code']!=0) {
            return $this->toJson(-2,$res['msg']);
        }
        return $this->toJson(0,'success',$res['data']);
    }

    //首页数据
    public function shouye()
    {
        $items = [
            'ads'=>[],
        ];
        $items['ads'] = $this->dbFront->getAds(); //首页横图
        $items['intro'] = $this->dhjieshao(); //大会介绍
        $items['agenda'] = $this->dhagenda(); //大会议程
        $videos = $this->dbFront->getVideoIndex(['start'=>0]);
        $items['videos'] = [ //大会视频
            'data'=>$videos['code']==0 ? $videos['data'] : [],
            'total'=>$videos['code']==0 ? $videos['total'] : 0,
        ];
        $sponsor = $this->dbFront->getSponsorIndex(); //赞助商
        $items['sponsors'] = $sponsor['code']==0 ? $sponsor['data'] : [];
        return $this->toJson(0,'success',$items);
    }

    //大会介绍
    public function dhjieshao()
    {
        $res = file_get_contents('dhjieshao.json');
        $res = json_decode($res,true);
        $res['detail'] = $res['detail'] ? json_decode($res['detail'],true) : '';
        return $res;
    }

    //大会议程
    public function dhagenda()
    {
        $res = file_get_contents('dhyicheng.json');
        $res = json_decode($res,true);
        return $res;
    }

    //大会视频
    public function getVideoIndex(Request $request)
    {
        $arys = $request->all();
        $pages['start'] = isset($arys['start'])&&$arys['start'] ? $arys['start'] : 0;
        $res = $this->dbFront->getVideoIndex($pages);
        if ($res['code']!=0) {
            return $this->toJson(-2,$res['msg']);
        }
        return $this->toJson(0,'success',$res['data'],$res['total']);
    }
}